﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using Microsoft.Practices.ObjectBuilder2;

namespace Simon.Unity.Proxy
{
   [AttributeUsage(AttributeTargets.Property, AllowMultiple=false)]
   public sealed class ParentAttribute : DependencyResolutionAttribute
   {
      public override IDependencyResolverPolicy CreateResolver(Type typeToResolve)
      {
         return new ParentDependencyRelosolverPolicy();
      }

      private class ParentDependencyRelosolverPolicy : IDependencyResolverPolicy
      {
         #region IDependencyResolverPolicy Members
         public object Resolve(IBuilderContext context)
         {
            return context.Policies.Get<IParentGetterPolicy>(null).Parent;
         }
         #endregion
      }
   }
}
